<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <title>Gogs中文文档 - 书栈(BookStack.CN)</title>
    <link href="editormd.css" rel="stylesheet">
</head>
<body>
    <h1 id="article-title">4.2 Web 钩子</h1>
    <div class="article-body markdown-body editormd-preview-container"  id="page-content">
        <div class="markdown-toc editormd-markdown-toc"><ul class="markdown-toc-list"><li><a class="toc-level-1" href="#Web 钩子" level="1">Web 钩子</a><ul><li><a class="toc-level-3" href="#事件信息" level="3">事件信息</a><ul></ul></li></ul></li></ul></div><h1 id="h1-web-"><a name="Web 钩子" class="reference-link"></a><span class="header-link octicon octicon-link"></span>Web 钩子</h1><p>Gogs 支持针对仓库事件的 Web 钩子服务，您可以在仓库的设置相关页面中找到（<code>/:username/:reponame/settings/hooks</code>）。所有的事件推送均为 POST 请求，目前支持 Gogs 和 Slack 两种格式的内容。</p>
<h3 id="h3-u4E8Bu4EF6u4FE1u606F"><a name="事件信息" class="reference-link"></a><span class="header-link octicon octicon-link"></span>事件信息</h3><p>以下为 Gogs 向 Payload URL 发送的事件信息示例：</p>
<pre class="prettyprint linenums prettyprinted" style=""><ol class="linenums"><li class="L0"><code><span class="pln">X</span><span class="pun">-</span><span class="typ">Gogs</span><span class="pun">-</span><span class="typ">Delivery</span><span class="pun">:</span><span class="pln"> f6266f16</span><span class="pun">-</span><span class="lit">1bf3</span><span class="pun">-</span><span class="lit">46a5</span><span class="pun">-</span><span class="lit">9ea4</span><span class="pun">-</span><span class="lit">602e06ead473</span></code></li><li class="L1"><code><span class="pln">X</span><span class="pun">-</span><span class="typ">Gogs</span><span class="pun">-</span><span class="typ">Event</span><span class="pun">:</span><span class="pln"> push</span></code></li><li class="L2"><code><span class="pln">X</span><span class="pun">-</span><span class="typ">Gogs</span><span class="pun">-</span><span class="typ">Signature</span><span class="pun">:</span><span class="pln"> </span><span class="lit">1921679ed6274399b6514721056337f6913b6ff1cb35a24d340e983745d637f1</span></code></li></ol></pre><pre class="prettyprint linenums prettyprinted" style=""><ol class="linenums"><li class="L0"><code class="lang-json"><span class="pun">{</span></code></li><li class="L1"><code class="lang-json"><span class="pln">  </span><span class="str">&#34;ref&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;refs/heads/develop&#34;</span><span class="pun">,</span></code></li><li class="L2"><code class="lang-json"><span class="pln">  </span><span class="str">&#34;before&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;28e1879d029cb852e4844d9c718537df08844e03&#34;</span><span class="pun">,</span></code></li><li class="L3"><code class="lang-json"><span class="pln">  </span><span class="str">&#34;after&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;bffeb74224043ba2feb48d137756c8a9331c449a&#34;</span><span class="pun">,</span></code></li><li class="L4"><code class="lang-json"><span class="pln">  </span><span class="str">&#34;compare_url&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;http://localhost:3000/unknwon/webhooks/compare/28e1879d029cb852e4844d9c718537df08844e03...bffeb74224043ba2feb48d137756c8a9331c449a&#34;</span><span class="pun">,</span></code></li><li class="L5"><code class="lang-json"><span class="pln">  </span><span class="str">&#34;commits&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span></code></li><li class="L6"><code class="lang-json"><span class="pln">    </span><span class="pun">{</span></code></li><li class="L7"><code class="lang-json"><span class="pln">      </span><span class="str">&#34;id&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;bffeb74224043ba2feb48d137756c8a9331c449a&#34;</span><span class="pun">,</span></code></li><li class="L8"><code class="lang-json"><span class="pln">      </span><span class="str">&#34;message&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;!@#0^%\u003e\u003e\u003e\u003e\u003c\u003c\u003c\u003c\u003e\u003e\u003e\u003e\n&#34;</span><span class="pun">,</span></code></li><li class="L9"><code class="lang-json"><span class="pln">      </span><span class="str">&#34;url&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;http://localhost:3000/unknwon/webhooks/commit/bffeb74224043ba2feb48d137756c8a9331c449a&#34;</span><span class="pun">,</span></code></li><li class="L0"><code class="lang-json"><span class="pln">      </span><span class="str">&#34;author&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L1"><code class="lang-json"><span class="pln">        </span><span class="str">&#34;name&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;Unknwon&#34;</span><span class="pun">,</span></code></li><li class="L2"><code class="lang-json"><span class="pln">        </span><span class="str">&#34;email&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;u@gogs.io&#34;</span><span class="pun">,</span></code></li><li class="L3"><code class="lang-json"><span class="pln">        </span><span class="str">&#34;username&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;unknwon&#34;</span></code></li><li class="L4"><code class="lang-json"><span class="pln">      </span><span class="pun">},</span></code></li><li class="L5"><code class="lang-json"><span class="pln">      </span><span class="str">&#34;committer&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L6"><code class="lang-json"><span class="pln">        </span><span class="str">&#34;name&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;Unknwon&#34;</span><span class="pun">,</span></code></li><li class="L7"><code class="lang-json"><span class="pln">        </span><span class="str">&#34;email&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;u@gogs.io&#34;</span><span class="pun">,</span></code></li><li class="L8"><code class="lang-json"><span class="pln">        </span><span class="str">&#34;username&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;unknwon&#34;</span></code></li><li class="L9"><code class="lang-json"><span class="pln">      </span><span class="pun">},</span></code></li><li class="L0"><code class="lang-json"><span class="pln">      </span><span class="str">&#34;timestamp&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;2017-03-13T13:52:11-04:00&#34;</span></code></li><li class="L1"><code class="lang-json"><span class="pln">    </span><span class="pun">}</span></code></li><li class="L2"><code class="lang-json"><span class="pln">  </span><span class="pun">],</span></code></li><li class="L3"><code class="lang-json"><span class="pln">  </span><span class="str">&#34;repository&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L4"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;id&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="lit">140</span><span class="pun">,</span></code></li><li class="L5"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;owner&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L6"><code class="lang-json"><span class="pln">      </span><span class="str">&#34;id&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="lit">1</span><span class="pun">,</span></code></li><li class="L7"><code class="lang-json"><span class="pln">      </span><span class="str">&#34;login&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;unknwon&#34;</span><span class="pun">,</span></code></li><li class="L8"><code class="lang-json"><span class="pln">      </span><span class="str">&#34;full_name&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;Unknwon&#34;</span><span class="pun">,</span></code></li><li class="L9"><code class="lang-json"><span class="pln">      </span><span class="str">&#34;email&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;u@gogs.io&#34;</span><span class="pun">,</span></code></li><li class="L0"><code class="lang-json"><span class="pln">      </span><span class="str">&#34;avatar_url&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;https://secure.gravatar.com/avatar/d8b2871cdac01b57bbda23716cc03b96&#34;</span><span class="pun">,</span></code></li><li class="L1"><code class="lang-json"><span class="pln">      </span><span class="str">&#34;username&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;unknwon&#34;</span></code></li><li class="L2"><code class="lang-json"><span class="pln">    </span><span class="pun">},</span></code></li><li class="L3"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;name&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;webhooks&#34;</span><span class="pun">,</span></code></li><li class="L4"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;full_name&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;unknwon/webhooks&#34;</span><span class="pun">,</span></code></li><li class="L5"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;description&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;&#34;</span><span class="pun">,</span></code></li><li class="L6"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;private&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">,</span></code></li><li class="L7"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;fork&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">,</span></code></li><li class="L8"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;html_url&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;http://localhost:3000/unknwon/webhooks&#34;</span><span class="pun">,</span></code></li><li class="L9"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;ssh_url&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;ssh://unknwon@localhost:2222/unknwon/webhooks.git&#34;</span><span class="pun">,</span></code></li><li class="L0"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;clone_url&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;http://localhost:3000/unknwon/webhooks.git&#34;</span><span class="pun">,</span></code></li><li class="L1"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;website&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;&#34;</span><span class="pun">,</span></code></li><li class="L2"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;stars_count&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span></code></li><li class="L3"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;forks_count&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="lit">1</span><span class="pun">,</span></code></li><li class="L4"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;watchers_count&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="lit">1</span><span class="pun">,</span></code></li><li class="L5"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;open_issues_count&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="lit">7</span><span class="pun">,</span></code></li><li class="L6"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;default_branch&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;master&#34;</span><span class="pun">,</span></code></li><li class="L7"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;created_at&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;2017-02-26T04:29:06-05:00&#34;</span><span class="pun">,</span></code></li><li class="L8"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;updated_at&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;2017-03-13T13:51:58-04:00&#34;</span></code></li><li class="L9"><code class="lang-json"><span class="pln">  </span><span class="pun">},</span></code></li><li class="L0"><code class="lang-json"><span class="pln">  </span><span class="str">&#34;pusher&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L1"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;id&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="lit">1</span><span class="pun">,</span></code></li><li class="L2"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;login&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;unknwon&#34;</span><span class="pun">,</span></code></li><li class="L3"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;full_name&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;Unknwon&#34;</span><span class="pun">,</span></code></li><li class="L4"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;email&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;u@gogs.io&#34;</span><span class="pun">,</span></code></li><li class="L5"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;avatar_url&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;https://secure.gravatar.com/avatar/d8b2871cdac01b57bbda23716cc03b96&#34;</span><span class="pun">,</span></code></li><li class="L6"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;username&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;unknwon&#34;</span></code></li><li class="L7"><code class="lang-json"><span class="pln">  </span><span class="pun">},</span></code></li><li class="L8"><code class="lang-json"><span class="pln">  </span><span class="str">&#34;sender&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span></code></li><li class="L9"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;id&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="lit">1</span><span class="pun">,</span></code></li><li class="L0"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;login&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;unknwon&#34;</span><span class="pun">,</span></code></li><li class="L1"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;full_name&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;Unknwon&#34;</span><span class="pun">,</span></code></li><li class="L2"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;email&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;u@gogs.io&#34;</span><span class="pun">,</span></code></li><li class="L3"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;avatar_url&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;https://secure.gravatar.com/avatar/d8b2871cdac01b57bbda23716cc03b96&#34;</span><span class="pun">,</span></code></li><li class="L4"><code class="lang-json"><span class="pln">    </span><span class="str">&#34;username&#34;</span><span class="pun">:</span><span class="pln"> </span><span class="str">&#34;unknwon&#34;</span></code></li><li class="L5"><code class="lang-json"><span class="pln">  </span><span class="pun">}</span></code></li><li class="L6"><code class="lang-json"><span class="pun">}</span></code></li></ol></pre>

    </div>
</body>
</html>